package ar.com.cubika.trainees.view.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ar.com.cubika.trainees.bean.transportes.Empresa;
import ar.com.cubika.trainees.bean.transportes.vehiculos.Vehiculo;

public class ShowVehiculoServlet extends TransportesServlet {
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Empresa empr = this.getEmpresa();
        PrintWriter output = response.getWriter();
        Vehiculo veh = empr.getVehiculo(request.getParameter("patente"));
        
        if (request.getSession().getAttribute("primerVehiculo") == null) {
            request.getSession().setAttribute("primerVehiculo", veh);
        }
        
        output.println("<html>");
        this.writeHtmlHead(empr, output);

        output.println("<body>");
        output.println("    <h2>" + veh.getTipoVehiculo() + " " + veh.getPatente() + "</h2>");
        
        output.println("&lt;carga m&aacute;xima&gt; " + veh.getCargaMaxima() + " kg");
        output.println("<br><br>");

        String urlEmpresa = response.encodeURL("showEmpresa");
        this.writeEndOfPage(
                "<a href=\"" + urlEmpresa + "\">Volver a la empresa</a>", 
                output);
    }

}
